home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Assemblers / hecasm / asm5.c < prev    next >
C/C++ Source or Header  |  1995-07-26  |  5KB  |  271 lines

  1. /* here are the routines to handle outputing the object code and */
  2. /* listing file */
  3.  
  4. #include "asm.h"
  5.  
  6. /* this is used if a byte addressable machine is chosen */
  7. #if (WSIZE == 1)
  8.  
  9. outlisting()
  10. {
  11. register char *cp;
  12. register int *wp;
  13. int nwords;
  14.  
  15. /* fill end of buffer with spaces */
  16. for(cp=eptr;cp<&ebuf[ERRMAX];*cp++ = ' ');
  17.  
  18. if (listmode == EMPTYLIS)
  19.     fprintf(lfp,"%.4s       ",ebuf);
  20. else
  21.     fprintf(lfp,"%.4s %.04x  ",ebuf, listaddr);
  22. if (listmode == NOCODLIS)
  23.     fprintf(lfp,"%17s%5d %s","",lineno, sbuf);
  24. else
  25.     {
  26.     nwords = cptr - cbuf;
  27.     wp = &cbuf[0];
  28.     switch(nwords)
  29.         {
  30.         case 0:
  31.             fprintf(lfp,"%16s","");
  32.             break;
  33.         case 1:
  34.             fprintf(lfp,"%02x%14s",wp[0]&BYTE,"");
  35.             break;
  36.         case 2:
  37.             fprintf(lfp,"%02x  %02x%10s",wp[0]&BYTE,wp[1]&BYTE,"");
  38.             break;
  39.         default:
  40.             fprintf(lfp,"%02x  %02x  %02x%6s",wp[0]&BYTE,wp[1]&BYTE,wp[2]&BYTE,"");
  41.             break;
  42.         }
  43.     fprintf(lfp,"%5d %s",lineno,sbuf);
  44.     wp += 3;
  45.     while ((nwords -= 3) > 0)
  46.         {
  47.         fprintf(lfp,"%11s","");
  48.         switch(nwords)
  49.             {
  50.             case 1:
  51.                 fprintf(lfp,"%02x\n",wp[0]&BYTE);
  52.                 break;
  53.             case 2:
  54.                 fprintf(lfp,"%02x  %02x\n",wp[0]&BYTE,wp[1]&BYTE);
  55.                 break;
  56.             default:
  57.                 fprintf(lfp,"%02x  %02x  %02x\n",wp[0]&BYTE,wp[1]&BYTE,wp[2]&BYTE);
  58.             }
  59.         wp +=3;
  60.         }
  61.     } 
  62. }
  63.  
  64.  
  65. #else
  66. /* this is compiled if it is a word addressable machine */
  67.  
  68. outlisting()
  69. {
  70. register char *cp;
  71. register int *wp;
  72. int nwords,address;
  73.  
  74. /* fill end of buffer with spaces */
  75. for(cp=eptr;cp<&ebuf[ERRMAX];*cp++ = ' ');
  76.  
  77. fprintf(lfp,"%.4s %.04x  ",ebuf, listaddr);
  78.  
  79. if (listmode == NOCODLIS)
  80.     fprintf(lfp,"%17s%5d %s","",lineno, sbuf);
  81. else
  82.     {
  83.     nwords = cptr - cbuf;
  84.     wp = &cbuf[0];
  85.     switch(nwords)
  86.         {
  87.         case 0:
  88.             fprintf(lfp,"%16s","");
  89.             break;
  90.         case 1:
  91.             fprintf(lfp,"%04x%12s",wp[0]&WORD,"");
  92.             break;
  93.         case 2:
  94.             fprintf(lfp,"%04x %04x%7s",wp[0]&WORD,wp[1]&WORD,"");
  95.             break;
  96.         default:
  97.             fprintf(lfp,"%04x %04x %04x%2s",wp[0]&WORD,wp[1]&WORD,wp[2]&WORD,"");
  98.             break;
  99.         }
  100.     fprintf(lfp,"%5d %s",lineno,sbuf);
  101.     wp += 3;
  102.     address=listaddr;
  103.     while ((nwords -= 3) > 0)
  104.         {
  105.         fprintf(lfp,"%.4s %.04x  ",ebuf, address += 3);
  106.         switch(nwords)
  107.             {
  108.             case 1:
  109.                 fprintf(lfp,"%04x\n",wp[0]&WORD);
  110.                 break;
  111.             case 2:
  112.                 fprintf(lfp,"%04x %04x\n",wp[0]&WORD,wp[1]&WORD);
  113.                 break;
  114.             default:
  115.                 fprintf(lfp,"%04x %04x %04x\n",wp[0]&WORD,wp[1]&WORD,wp[2]&WORD);
  116.             }
  117.         wp +=3;
  118.         }
  119.     }
  120. }
  121. #endif
  122.  
  123.  
  124. /*
  125.  * Output code word.
  126.  * Save it in the per line
  127.  * buffer for outlisting.
  128.  * Update dot.
  129.  */
  130. codew(b)
  131. int b;
  132. {
  133.  
  134. /* fake it on the first pass */
  135. if (!pass)
  136.     {
  137.     dot->s_value++;
  138.     return;
  139.     }
  140.  
  141. /* mask it to the correct size */
  142. #if (WSIZE == 1)
  143. b &= 0x0ff;
  144. #else
  145. b &= 0x0ffff;
  146. #endif
  147.  
  148. /* put it in the code buffer */
  149. if(cptr < &cbuf[CLMAX])
  150.     *cptr++ = b;
  151. else
  152.     err('d',"code buffer overflow");
  153.  
  154. /* if the buffer is full, or the code is non contiguous flush the buffer */
  155. if (!nflag)
  156.     { 
  157.     if(crec >= CBMAX || cadr + crec != dot->s_value) 
  158.         {
  159.         cflush();
  160.     /* new buffer address */
  161.         cadr = dot->s_value;
  162.         }
  163.     crbf[crec++] = b;
  164.     }
  165.  
  166. /* increment the location counter */
  167. dot->s_value++;
  168. }
  169.  
  170.  
  171. /*
  172.  * Flush the binary code
  173.  * buffer.
  174.  */
  175. cflush()
  176. {
  177. register int i;
  178.  
  179. if(crec == 0)
  180.     return;
  181. fprintf(ofp,"%04x/",cadr);
  182. for(i=0; i<crec; ++i)
  183.     {
  184. #if (WSIZE == 1)
  185.     fprintf(ofp, "%02x", crbf[i]&BYTE);
  186. #else
  187.     fprintf(ofp, "%04x", crbf[i]&WORD);
  188. #endif
  189.     }
  190. fprintf(ofp,"\n");
  191. crec = 0;
  192. }
  193.  
  194.  
  195. err(c,s)
  196. int c;
  197. char *s;
  198. {
  199. if (!pass)
  200.     return;
  201.  
  202. fprintf(stderr,"%04d %s\n",lineno,s);
  203.  
  204. if(eptr >= &ebuf[ERRMAX])
  205.     {
  206.     fprintf(stderr,"\ntoo many errors on a line.\n");
  207.     exit(1);
  208.     }
  209. *eptr++ = c;
  210. }
  211.  
  212.  
  213.  
  214. /*
  215.  * Print out the symbol table to Listing
  216.  */
  217. symprt()
  218. {
  219. register struct sym *stp, *uptr;
  220. register struct reflst *ref;
  221. struct reflst *ref1, *ref2;
  222. int i,r,symcnt = 0;
  223. char c1;
  224.  
  225. fprintf(lfp,"\14\n");
  226. uptr = &ust[USERMAX];
  227. for (stp=ust; stp < uptr; stp++) 
  228.     if (stp->s_used)
  229.         {
  230.         symcnt++;
  231.         if (stp->s_flag && SF_ASG) 
  232.             c1 = '='; 
  233.         else 
  234.             c1 = ' ';
  235.         fprintf(lfp,"\t%-8s    %c %04x    ",stp->s_name,c1,stp->s_value);
  236.         ref1 = stp->s_ref;
  237.         ref = NULL;
  238.         while (ref1 != NULL) 
  239.             {
  240.             ref2 = ref1;
  241.             ref1 = ref1->r_chain;
  242.             ref2->r_chain = ref;
  243.             ref = ref2;
  244.             }
  245.         i = LREFMAX;
  246.         while (ref!=NULL) 
  247.             {
  248.             r=ref->r_stmtno;
  249.             if(r<0) 
  250.                 {
  251.                 r = -r;
  252.                 c1 = '#';
  253.                 } 
  254.             else 
  255.                 c1 = ' ';
  256.             fprintf(lfp,"%5d%c",r,c1);
  257.             ref=ref->r_chain;
  258.             i--;
  259.             if (!i && ref!=NULL) 
  260.                 {
  261.                 fprintf(lfp,"\n\t\t\t      ");
  262.                 i=LREFMAX;
  263.                 }
  264.             }
  265.         fprintf(lfp,"\n");
  266.         }
  267. fprintf(lfp,"\n%6d Symbols\n%6d References\n",symcnt,refcnt);
  268. return;
  269. }
  270.  
  271.